﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_SZJBXX_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDrop();
        }
        txtUserID.Attributes.Add("ReadOnly", "true");
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateSZJBXX();
    }

    // 删除
    protected void lvDate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int KeyID = DongDong.Common.Misc.ConvertToInt(lvDate.DataKeys[e.ItemIndex].Value);
        SZJBXX.BadDelete(KeyID);
        lvDate.EditIndex = -1;
        PopulateSZJBXX();
    }

    // 查询
    public void PopulateSZJBXX()
    {
        lvDate.DataSource = SZJBXX.GetAllByCondition(DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpQu.SelectedValue), txtName.Text, DongDong.Common.Misc.ConvertToInt(drpUserType.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpEduLevel.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpGKXM.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpGKJL.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpRZStatus.SelectedValue), txtTelphone.Text, DongDong.Common.Misc.ConvertToInt(drpSZStatus.SelectedValue), DongDong.Common.Misc.ConvertToInt(hdlUserID.Value), txtAddTimeFrom.Text, txtAddTimeTo.Text);
        lvDate.DataBind();
    }

    // 获得详细师资基本信息
    public string GetSZJBXXDetail(object ID, object Xing, object Ming)
    {
        string Return = "暂无资料";
        string xing = Xing.ToString();
        string ming = Ming.ToString();
        if (!string.IsNullOrEmpty(xing) && !string.IsNullOrEmpty(ming))
        {
            Return = "<a target='_blank' href='../../Admin/SZJBXX/DetailManage.aspx?SZID=" + DongDong.Common.Misc.ConvertToInt(ID) + "'>" + xing + ming + "</a>";
        }
        return Return;
    }

    // 获得所属机构信息
    public string GetIsJG(object ID)
    {
        string Return = "暂无资料";
        //SZJBXX objSZJBXX = SZJBXX.GetByID(DongDong.Common.Misc.ConvertToInt(ID));
        //if (objSZJBXX != null)
        //{
        //    Return = "<a target='_blank' href='../../Admin/SZJBXX/DetailManage.aspx?ID=" + objSZJBXX.ID + "'>" + objSZJBXX.Xing + objSZJBXX.Ming + "</a>";
        //}
        if ("0".Equals(DongDong.Common.Misc.ConvertToInt(ID)))
        {
            Return = "个人";
        }
        else
        {
            Return = "<a target='_blank' href='www.baidu.com'>" + "www.baidu.com" + "</a>";
        }
        return Return;
    }

    // 获得用户名
    public string GetUserName(object UserID)
    {
        string Return = "暂无资料";
        Client objClient = Client.Get(DongDong.Common.Misc.ConvertToInt(UserID));
        if (objClient != null)
        {
            Return = "<a target='_blank' href='../../Admin/Client/Add.aspx?UserID=" + objClient.ID + "'>" + objClient.Username + "</a>";
        }
        return Return;
    }

    // 绑定下拉框
    public void PopulateDrop()
    {
        drpUserType.PopulateFromEnum<SZJBXX.typeUser>();
        drpUserType.Items.Insert(0, new ListItem("请选择", "999"));
        drpEduLevel.PopulateFromEnum<SZJBXX.LevelEdu>();
        drpEduLevel.Items.Insert(0, new ListItem("请选择", "999"));
        drpGKXM.PopulateFromEnum<SZJBXX.IsOrNot>();
        drpGKXM.Items.Insert(0, new ListItem("全部", "999"));
        drpGKJL.PopulateFromEnum<SZJBXX.IsOrNot>();
        drpGKJL.Items.Insert(0, new ListItem("全部", "999"));
        drpRZStatus.PopulateFromEnum<SZJBXX.statusSMRZ>();
        drpRZStatus.Items.Insert(0, new ListItem("请选择", "999"));
        drpSZStatus.PopulateFromEnum<SZJBXX.statusSZ>();
        drpSZStatus.Items.Insert(0, new ListItem("请选择", "999"));

        drpSheng.DataSource = S_Province.GetAll();
        drpSheng.DataValueField = "ProvinceID";
        drpSheng.DataTextField = "ProvinceName";
        drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpShi.Items.Insert(0, new ListItem("请选择", "0"));

        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        drpShi.DataSource = S_City.GetAllByCondition(ParentID, "");
        drpShi.DataValueField = "CityID";
        drpShi.DataTextField = "CityName";
        drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        drpQu.DataSource = S_District.GetAllByCondition(ParentID, "");
        drpQu.DataValueField = "DistrictID";
        drpQu.DataTextField = "DistrictName";
        drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    // 获得省市区名称
    public string GetShengShiQuName(object sheng, object shi, object qu)
    {
        string Return = "暂无资料";
        Return = S_District.GetPName_CName_RNameByPID_CID_RID(sheng, shi, qu);
        return Return;
    }

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateSZJBXX();
    }
}